<?php
/**
 * 新闻分类模型
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class NewCat extends Model
{
    /**
     *定义数据库表
     * @var string
     */
    protected $table = 'news_cat';
    /**
     *定义模型变量
     * @var
     */
    protected $newCatModel;
    /**
     *模型属性定义
     * @var
     */
    public $id;
    public $pid;
    public $status;
    public $title;
    public $description;
    public $is_delete;
    public $psort;

    /**
     *构造函数初始化模型
     * NewCat constructor.
     */
    public function __construct()
    {
        $this->newCatModel = DB::table($this->table);
    }

    /**
     *获取新闻分类列表
     * @param $params
     * @return array
     */
    public function getlist($params){
        $data=[];
        if($params['getcount']){
            $data['total'] = $this->newCatModel->where($params['where'])->count();
        }
        if($params['getfield']){
            $data['row'] = $this->newCatModel->where($params['where'])->orderByDesc($params['order'])->select($params['field'])->get()->toArray();
        }else{
            $data['row'] = $this->newCatModel->where($params['where'])->orderByDesc($params['order'])->select($params['field'])->offset($params['page'])->limit($params['count'])->get();
        }
        return $data;
    }


}
